class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        string curS = "";
        int res = 0;
        for (int i = 0; i < s.length(); i++)
        {
            auto n =  curS.find(s[i]);
            if (n != string::npos)
            {
                res = max(res, (int)curS.length());
                curS.erase(0, n + 1);
            }
            curS += s[i];
        }
        return max(res, (int)curS.length());
    }
};
